package com.second.app.thread.wait.o;

/**
 * @Author GYZ
 * <pre>
 *
 * </pre>
 */
public class WaitFewSeconds {

    public static void main(String[] args) {

        new Thread(Entity::doMethod,"线程A").start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(Entity::doQMethod,"线程B").start();
    }
}

class Entity{

    private static final Object lock = new Object();

    public static void doMethod(){

        synchronized (lock){
            System.out.println("wait begin timer="+System.currentTimeMillis());
            try {
                lock.wait(30000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("wait end timer="+System.currentTimeMillis());
        }

    }
    public static void doQMethod(){

        synchronized (lock){
            System.out.println("notify begin timer="+System.currentTimeMillis());
            try {
                lock.wait(5000);
                lock.notify();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("notify end timer="+System.currentTimeMillis());
        }
    }
}
